package com.mall.util.ratelimit;

import java.util.concurrent.TimeUnit;

public class TimeUtil {

    private static volatile long currentTimeMillis;

    static {
        currentTimeMillis = System.currentTimeMillis();

        Thread daemon = new Thread(() -> {
           while (true) {
               currentTimeMillis = System.currentTimeMillis();

               try {
                   TimeUnit.MILLISECONDS.sleep(1);
               } catch (InterruptedException e) {
                   // ignore
               }
           }
        });

        daemon.setName("å-time-tick-thread");
        daemon.setDaemon(true);
        daemon.start();
    }

    public static long currentTimeMillis() {
        return currentTimeMillis;
    }
}
